package com.nondo.dean.product.controller.api.inner;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.nondo.dean.common.annotation.ApiVersion;
import com.nondo.dean.product.domain.ProductType;
import com.nondo.dean.product.service.ProductTypeService;


@RestController("apiInnerProductType")
@RequestMapping("/{v}/inner/product/type")
public class ProductTypeController {

    @Autowired
    private ProductTypeService productTypeService;

    /**
     * 接收sap返回的产品类型数据进行入库
     * @param productResult
     * @return
     */
    @ApiVersion(1)
    @RequestMapping("/sapSync")
    public int sapSync(@RequestBody String productResult) {
        Object jsonObject = JSON.parse(productResult);
        String jsonString = jsonObject.toString();
        List<ProductType>  collection = JSONObject.parseArray(jsonString, ProductType.class);
        int count= productTypeService.synchronousProductData(collection);

        return count;
    }
    
}
